// pages/user/register/index/requirement/requirement.js
import Dialog from "@vant/weapp/dialog/dialog";
import Notify from "@vant/weapp/notify/notify";
Component({
    /*
    * 接收外部样式
    * */
    options: {
        addGlobalClass: true,
        styleIsolation: "shared"
    },

    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        _radio1: "",
        _radio2: "",
        _radio3: ""
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onChange: async function(e) {
            let name = e.currentTarget.dataset.name;
            let value =  e.detail;
            this.setData({["_" + name]: value})
            switch (name){
                case "radio1":
                    if (value !== "2") {
                        await Dialog.alert({
                            title: "提示",
                            message: "您没有通过合格投资者认证",
                            context: this,
                            selector: "#van-dialog-requirement"
                        })
                        this.setData({["_" + name]: ""})
                        return false
                    }
                    break
                case "radio2":
                    if (value !== "1") {
                        await Dialog.alert({
                            title: "提示",
                            message: "您没有通过合格投资者认证",
                            context: this,
                            selector: "#van-dialog-requirement"
                        })
                        this.setData({["_" + name]: ""})
                        return false
                    }
                    break
                case "radio3":
                    if (value !== "1") {
                        await Dialog.alert({
                            title: "提示",
                            message: "您没有通过合格投资者认证",
                            context: this,
                            selector: "#van-dialog-requirement"
                        })
                        this.setData({["_" + name]: ""})
                        return false
                    }
                    break
            }
        },
        bindToNext: async function () {
            let radio1 = this.data._radio1;
            let radio2 = this.data._radio2;
            let radio3 = this.data._radio3;
            if (radio1 && radio2 && radio3) {
                this.triggerEvent("requirement", {}, {}); //组件接收函数写入数据
            } else {
                Notify({
                    type: "warning",
                    message: "请先完成合格投资者认证",
                    context: this,
                    selector: "#van-notify-requirement"
                });
                return false
            }
        }
    }
})
